Plot Using hist3D
## mod_factor
## result_factor 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
## 0 113 14 2 1
## 1 257 51 7
## 2 265 134 20 3
## 3 217 211 83 11 1
## 4 97 228 119 29 9
## 5 39 178 183 79 17 1
## 6 8 101 203 116 31 2 1
## 7 4 44 172 164 81 14 2
## 8 25 108 191 127 29 4
## 9 11 60 150 161 72 9
## 10 2 21 109 175 112 25 1
## 11 1 19 89 151 161 60 8
## 12 2 40 122 198 123 24
## 13 14 69 161 171 67 1
## 14 1 4 39 118 201 132 6
## 15 12 79 175 173 41
## 16 3 35 130 204 75
## 17 2 14 72 181 188
## 18 4 22 135 295
## 19 5 62 282
## 20 13 112

## Loading required package: rgl


Initial Hist
## Output at: 3d_hist_1.gif
## [1] TRUE

Building Up Histogram
## Output at: 3d_hist_build_up.gif
## [1] TRUE

## [1] "row 1 , col 1 : 2"
## [1] "0 < 2"
## [1] "new_table 1 1 = 1"
## [1] "row 1 , col 2 : 3"
## [1] "0 < 3"
## [1] "new_table 1 2 = 1"
## [1] "row 1 , col 3 : 2"
## [1] "0 < 2"
## [1] "new_table 1 3 = 1"
## [1] "row 2 , col 1 : 0"
## [1] "row 2 , col 2 : 0"
## [1] "row 2 , col 3 : 8"
## [1] "0 < 8"
## [1] "new_table 2 3 = 1"
## [1] "row 3 , col 1 : 3"
## [1] "0 < 3"
## [1] "new_table 3 1 = 1"
## [1] "row 3 , col 2 : 2"
## [1] "0 < 2"
## [1] "new_table 3 2 = 1"
## [1] "row 3 , col 3 : 0"
## b
## a 0 2 8
## 5 1 1 1
## 7 0 0 1
## 10 1 1 0
## Output at: 3d_hist_build_up_1.gif
## [1] TRUE


Say We Start with p = .4
mod <- seq(0, 1, 0.1)
rep <- 1:1000
tosses <- 20
x_point_4 <- crossing(mod, rep) %>%
mutate(result = rbinom(n = nrow(.), size = tosses, prob = mod)) %>%
filter(mod == .4)
## Create cuts:
result_factor <- as.factor(x_point_4$result)
mod_factor <- as.factor(x_point_4$mod)
result_cut <- cut(x_point_4$result, 21)
mod_cut <- cut(x_point_4$mod, 11)
## Calculate joint counts at cut levels:
z <- table(result_cut, mod_cut)
z_factor_4 <- table(result_factor, mod_factor)
# assign NA values to all groups with 0
z_factor_4[z_factor_4 == "0"] <- NA
# assign NA values to all groups with 1000 because skews plot too much
z_factor_4[z_factor_4 == "1000"] <- NA
Turn Only p = .4 A Color
colvar <- structure(rep(1, prod(dim(z_factor))), .Dim =dim(z_factor), .Dimnames = dimnames(z_factor))
colvar[ ,5] <- 2
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## NA NA NA NA 7 13 43 74 112 168 178 156 124 64 40 15 4 2 NA NA
## 20
## NA



## Output at: 3d_hist_build_up_full_3.gif
## [1] TRUE

# take in current_matrix generated from the making the distribution for point_4 to start from there
current_matrix
vectorOfTables_2 <- vector(mode = "list")
vectorOfTables_2[[1]] <- current_matrix
####3 something wrong here: fix it!
# repeat
# how can we make this more efficient? If row is done or completed, don't allow it to be sampled...
# only go up to 200 because 1000 takes too long, but could change this later. Didn't want to do 100 because distributions weren't looking great
while (count < 201) {
# only randomly sample from the rows that have real numbers
row = sample(2:14, 1)
# print(paste("count", count, "row", row))
# make sure we haven't sampled an NA value
if (is.na(current_matrix)[row,5]) {
current_matrix[row, 5] = z_factor[row, 5]
}
# if not NA and the number in the current matrix is less than the final matrix, add one
else if (current_matrix[row, 5] < z_factor_0s[row, 5]){
current_matrix[row,5] <- current_matrix[row,5] + 1
count = count + 1
# add the new matrix to the list of matrices
vectorOfTables_2[[count + 1]] <- current_matrix
}
}
# vectorOfTables